<?php

class ViewMember extends MY_Controller {

    public function __construct() {
        parent::__construct();
        
        if($this->session->userdata('user_type') != 1 || $this->session->userdata('user_type') == null){
            show_error("You have no permission here");
        }
    }

    function index() {
        $this->load->library('pagination');
        $this->load->library('table');


        $config['base_url'] = 'http://localhost/AsNew/ci/index.php/Approve/index';
        $config['total_rows'] = $this->db->get('MEMBER')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 20;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';

        $this->pagination->initialize($config);

        $this->load->model('Member_Model');
        $query = $this->Member_Model->getAllMember($config['per_page'], $this->uri->segment(3));
        $result = $query->result();

//        $this->table->set_heading('No.', 'First Name', 'Last Name', 'ID Card', 'Status', 'Manage'); //Create columns
        $this->table->set_heading('No.', 'First Name', 'Last Name', 'ID Card', 'Manage'); //Create columns

        if ($query->num_rows() > 0) {
            for ($i = 0; $i < count($result); $i++):
                $row = $result[$i];
                $this->table->add_row(
                        $i+1, 
                        $row->FIRSTNAME, 
                        $row->LASTNAME, 
                        $row->ID_CARD, 
//                        $row->APPROVE_FLAG ? 'Approved' : 'Waiting for Approve', 
                        anchor( base_url().'index.php/Signup/getMember/View/'.$row->ID, '<img src="'.base_url().'images/view.png" alt="View" />' ) 
                        ); 
            endfor;
        }else {
            $cell = array('data' => 'No results found', 'colspan' => 4, 'align' => 'center');
            $this->table->add_row($cell);
        }

        $tmpl = array(
            'table_open' => '<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">',
            'heading_cell_start' => '<th class="table-header-repeat line-left"><a href>',
            'heading_cell_end' => '</a></th>',
            'table_close' => '</table>');

        $this->table->set_template($tmpl);
        $this->data['main_content'] = 'approve_member';
        $this->load->view('includes/template', $this->data);
    }

    function searchMember() {
        $this->load->library('pagination');
        $this->load->library('table');


//        $config['base_url'] = 'http://localhost/AsNew/ci/index.php/Approve/index';
        $config['total_rows'] = $this->db->get('MEMBER')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 20;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';

        $this->pagination->initialize($config);

        $search_firstname = $this->input->post('search_firstname');
        $search_lastname = $this->input->post('search_lastname');
        $search_citizenid = $this->input->post('search_citizenid');
//        $search_flag = $this->input->post('search_flag');

        $this->load->model('Member_Model');
        $query = $this->Member_Model->searchMember($search_firstname, $search_lastname, $search_citizenid, $config['per_page'], $this->uri->segment(3));
        $result = $query->result();

//        $this->table->set_heading('No.', 'First Name', 'Last Name', 'ID Card', 'Status', 'Manage'); //Create columns
        $this->table->set_heading('No.', 'First Name', 'Last Name', 'ID Card', 'Manage'); //Create columns

        if ($query->num_rows() > 0) {
            for ($i = 0; $i < count($result); $i++):
                $row = $result[$i];
                $this->table->add_row(
                        $i + 1, 
                        $row->FIRSTNAME, 
                        $row->LASTNAME, 
                        $row->ID_CARD, 
//                        $row->APPROVE_FLAG ? 'Approved' : 'Waiting for Approve', 
                        anchor(base_url() . 'index.php/Signup/getMember/View/' . $row->ID, '<img src="' . base_url() . 'images/view.png" alt="View" />')
                );
            endfor;
        }else {
            $cell = array('data' => 'No results found', 'colspan' => 6, 'align' => 'center');
            $this->table->add_row($cell);
        }

        $tmpl = array(
            'table_open' => '<table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">',
            'heading_cell_start' => '<th class="table-header-repeat line-left"><a href>',
            'heading_cell_end' => '</a></th>',
            'table_close' => '</table>');

        $this->table->set_template($tmpl);

        $this->data['main_content'] = 'approve_member';
        $this->load->view('includes/template', $this->data);
    }

    function gotoMemberPage() {
        $this->data['main_content'] = 'signup_test';
        $this->load->view('includes/template', $this->data);
    }

}

?>
